/**
 * 扬尘警示列表dustWarning.js
 * 版本号： v1.0.0
 */
$(function () {
    $("#dustWarning_dataList").datagrid({
        fit: true,
        fitColumns: true,
        method: "POST",
        rownumbers: true,
        singleSelect: true,
        pagination: true,
        border: false,
        pageSize: 10,
        pageNumber: 1,
        pageList: [10, 30, 50, 100], url: CONTEXT_PATH + '/dustWarning/dustWaringList.do',
        idField: 'dpcpId',
        frozenColumns: [[
            {field: 'dpcpId', checkbox: true}
        ]],
        columns: [
            [
                {field: 'dpcpName', title: '设备名称', width: 200, align: 'left',fixed: true},
                {field: 'deviceId', title: '设备编号', width: 165, fixed: true},
                {
                    field: 'cname', title: '所属项目', width: 240, fixed: true,
                    formatter: function (value) {
                        if (value) {
                            return value.prName
                        }
                    }
                },
                {field: 'principal', title: '施工单位名称', width: 240, fixed: true},
                {
                    field: 'alarmCategory', title: '警示类别', width: 140, fixed: true,
                    formatter: function (val) {
                        if (val == 1) return "<span style='color: green; font-weight: bold'>警报</span>";
                        if (val == 2) return "<span style='color: red; font-weight: bold'>预警</span>";
                    }
                },
                {
                    field: 'alarmTime', title: '报警时间', width: 140,
                    formatter: function (val) {
                        if (val) {
                            return formatDatebox(val, "yyyy-MM-dd HH:mm:ss")
                        }
                    }
                }
            ]
        ],
        onLoadSuccess: function (data) {
            if (data.rows.length > 0) {
                $("#dustWarning_dataList").datagrid("selectRow", 0);
            }
        }
    });


    //定义可操作按钮
    $("#dustWarning_menu").datagrid({
        border: false,
        fit: true,
        toolbar: createToolbar()
    });


});


/**
 * 创建toolbar按钮组
 * @returns {Array}
 */
function createToolbar() {
    var toolbar = [];
    var falg = false;
    for (var j = 0; j < btnOptions.length; j++) {
        if (false != btnOptions[j].value) {
            falg = true;
            break;
        }
    }
    if (!falg) {
        //不存在按钮
        toolbar.push({});
    } else {
        //存在按钮
        for (var i = 0; i < btnOptions.length; i++) {
            if (false != btnOptions[i].value) {
                //查询按钮
                if ("searchBtn" == btnOptions[i].key) {
                    toolbar.push({
                        id:btnOptions[i].value.meId,
                        text:btnOptions[i].value.name,
                        iconCls:btnOptions[i].value.iconCls,
                        handler: function () {
                            dustWarning_loadSearch();
                        }
                    });
                }
                //刷新按钮
                if ("refreshBtn" == btnOptions[i].key) {
                    toolbar.push({
                        id:btnOptions[i].value.meId,
                        text:btnOptions[i].value.name,
                        iconCls:btnOptions[i].value.iconCls,
                        handler: function () {
                            $("#dustWarning_dataList").datagrid("reload", {});
                        }
                    });
                    //导出按钮
                    if ("exportBtn" == btnOptions[i].key) {
                        toolbar.push({
                            id:btnOptions[i].value.meId,
                            text:btnOptions[i].value.name,
                            iconCls:btnOptions[i].value.iconCls,
                            handler: function () {
                                $("#dustWarning_dataList").datagrid("reload", {
                                    companyId: $("#companyId").val(),
                                    prId: $("#prId").val()
                                });
                            }
                        });
                    }
                }
            }
        }
        return toolbar;
    }
}


/**
 * 加载查询
 */
function dustWarning_loadSearch() {
    $("#dustWarningQuery_dialog").dialog({
        title: '查询警示信息',
        width: 380,
        modal: true,
        closed: true,
        height: 340,
        iconCls: "icon-custom-search",
        buttons: [{
            text: "查询",
            iconCls: "icon-role-state-ok",
            handler: function () {
                dustWarning_doSearch();
            }
        }, {
            text: "取消",
            iconCls: "icon-role-state-no",
            handler: function () {
                $('#dustWarningQuery_dialog').dialog('close');
            }
        }]
    });

    $("#parentIdTree").combotree("setValue", '');
    $("#prId_").combotree("setValue", '');
    $("#situation").combotree("setValue", '');
    $("#startDate").combotree("setValue", '');
    $("#endDate").combotree("setValue", '');

    $("#dustWarningQuery_dialog").dialog("move", {left: 450, top: 100});
    $("#dustWarningQuery_dialog").dialog('open');
}


/**
 * 执行查询
 */
function dustWarning_doSearch() {
    //刷新dg页码
    refreshPageNumber("dustWarning_dataList");
    $("#dustWarning_dataList").datagrid("reload", {
        companyId: $("#companyId").val(),
        prId: $("#prId").val()
    });
    $('#dustWarning_dataList').dialog('close');
}














